package com.opensns.android;

public class OauthAccessToken {
	
	public static final String SINAWEIBO_TOKEN = "sina_weibo_token";
	
	public static final String RENREN_TOKEN = "renren_token";
	
	public String platform;

	public String accessToken;
	
	public String refreshToken;
	
	public long expiresIn;
	
	/**
	 * 新浪微博：授权后返回的用户标识。
	 */
	public String uid;
	
	/**
	 * 人人网：Access Token 授权的访问范围。
	 */
	public String scope;
	
	public OauthAccessToken(String platform) {
		this.platform = platform;
	}
	
	public void setExpiresIn(String expiresIn) {
		setExpiresIn(Long.parseLong(expiresIn) * 1000);
	}
	
	public void setExpiresIn(long expiresIn) {
		this.expiresIn = System.currentTimeMillis() + expiresIn;
	}
	
	public boolean isExpired() {
		return (System.currentTimeMillis() < expiresIn);
	}
	
	public boolean isValid() {
		return (accessToken != null && accessToken.length() > 0 && isExpired());
	}
	
	public static boolean isTokenValid(OauthAccessToken token) {
		return (token != null && token.isValid());
	}
}
